/*****


系统时钟滴答相关，及延时函数等


**************/


#include "SysTick.h"

volatile uint32_t sys_tick_con=0;

tTickStart tickstart[TICKSTART_SIZE]=
{
	{TICK_DISABLE,0},
	{TICK_DISABLE,0},
	{TICK_DISABLE,0},
	{TICK_DISABLE,0},
	{TICK_DISABLE,0},
	{TICK_DISABLE,0},
	{TICK_DISABLE,0},
	{TICK_DISABLE,0},
	{TICK_DISABLE,0},
	{TICK_DISABLE,0},
};


Tick_StatusTypeDef Start_Tick(uint16_t tick)
{
//	if(TICK_DISABLE==tickstart[tick].start)
	{
		tickstart[tick].start=TICK_ENABLE;
		tickstart[tick].time=0;
		return TICK_OK;
	}
//	else
//	{
//		return TICK_ERROR;
//	}
}

Tick_StatusTypeDef Stop_Tick(uint16_t tick)
{
	if(TICK_ENABLE==tickstart[tick].start)
	{
		tickstart[tick].start=TICK_DISABLE;
		tickstart[tick].time=0;
		return TICK_OK;
	}
	else
	{
		return TICK_ERROR;
	}
}

void SYS_Delay_ms(uint32_t delay)
{
    // Wait delay ms
    uint32_t startTick; 
		startTick= sys_tick_con;//,temp=delay;
    while((startTick+delay)>=sys_tick_con);
}


extern		volatile	uint32_t			SysTimeUnix;
extern 		volatile 	uint32_t			SysRunTimeSec;
extern		volatile 	uint32_t			NetAtUnix;


void HAL_SYSTICK_Callback(void)
{
	uint8_t temp;
	sys_tick_con++;
	for(temp=0;temp<TICKSTART_SIZE;temp++)
	{
		if(tickstart[temp].start)
		{
			tickstart[temp].time++;
		}
	}
}




